#####
## September 2019
## Run this code file third in Stata
## This performs data cleaning for appendix analyses
#####


*** get scaled estimates and merge with cleaned data ***

use "Survey_Data.dta", clear
destring yob_wave1, replace ignore("NA")
gen age = (2016 - yob)/100
gen agesquared = age^2

gen somecollege = educ == 1
replace somecollege = . if mi(educ)
gen college = educ == 2
replace college = . if mi(educ)

*** clean knowledge ***

forvalues i = 1(1)5 { // dk means dk
	replace polinfo`i'_wave1 = "0" if polinfo`i'_wave1 == "NA"
}
destring polinfo*, replace ignore("NA")
gen pk1 = .
replace pk1 = 1 if polinfo1_wave1 == 3
replace pk1 = 0 if inlist(polinfo1_wave1, 1, 2, 0)
gen pk2 = .
replace pk2 = 1 if polinfo2_wave1 == 1
replace pk2 = 0 if inlist(polinfo2_wave1, 2, 3, 0)
gen pk3 = .
replace pk3 = 1 if polinfo3_wave1 == 2
replace pk3 = 0 if inlist(polinfo3_wave1, 1, 3, 4, 0)
gen pk4 = .
replace pk4 = 1 if polinfo4_wave1 == 3
replace pk4 = 0 if inlist(polinfo4_wave1, 1, 2, 4, 5, 0)
gen pk5 = .
replace pk5 = 1 if polinfo5_wave1 == 3
replace pk5 = 0 if inlist(polinfo5_wave1, 1, 2, 4, 5, 0)
cor pk*
gen pkav = (pk1 + pk2 + pk3 + pk4 + pk5)/5

saveold "Survey_Data_Cleaned.dta", replace
